package com.z001.snack.admin.module.business.category.controller;

import com.z001.snack.admin.common.AdminBaseController;
import com.z001.snack.admin.constant.AdminOperateLogTagConst;
import com.z001.snack.admin.module.business.category.domain.req.CategoryAddReq;
import com.z001.snack.admin.module.business.category.domain.req.CategoryTreeQueryReq;
import com.z001.snack.admin.module.business.category.domain.req.CategoryUpdateReq;
import com.z001.snack.admin.module.business.category.domain.resp.CategoryResp;
import com.z001.snack.admin.module.business.category.domain.resp.CategoryTreeResp;
import com.z001.snack.admin.module.business.category.service.CategoryService;
import com.z001.snack.common.common.domain.BaseResponse;
import com.z001.snack.common.module.support.operatelog.annoation.Api;
import com.z001.snack.common.module.support.operatelog.annoation.ApiOperation;
import com.z001.snack.common.module.support.operatelog.annoation.EnableOperateLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 类目
 *
 * @Author 1024创新实验室: 胡克
 * @Date 2021/08/05 21:26:58
 * @Wechat zhuoda1024
 * @Email lab1024@163.com
 * @Copyright 1024创新实验室 （ https://1024lab.net ），2012-2022
 */
@EnableOperateLog
@RestController
@Api(tags = AdminOperateLogTagConst.Business.MANAGER_CATEGORY)
public class CategoryController extends AdminBaseController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 添加类目
     * @param addForm
     * @return
     */
    @ApiOperation("添加类目")
    @PostMapping("/category/add")
    public BaseResponse<String> add(@RequestBody @Valid CategoryAddReq addForm) {
        return categoryService.add(addForm);
    }

    @ApiOperation("更新类目")
    @PostMapping("/category/update")
    public BaseResponse<String> update(@RequestBody @Valid CategoryUpdateReq updateForm) {
        return categoryService.update(updateForm);
    }

    @ApiOperation("查询类目详情")
    @GetMapping("/category/{categoryId}")
    public BaseResponse<CategoryResp> queryDetail(@PathVariable String categoryId) {
        return categoryService.queryDetail(categoryId);
    }

    @ApiOperation("查询类目层级树")
    @PostMapping("/category/tree")
    public BaseResponse<List<CategoryTreeResp>> queryTree(@RequestBody @Valid CategoryTreeQueryReq queryForm) {
        return categoryService.queryTree(queryForm);
    }

    @ApiOperation("删除类目")
    @GetMapping("/category/delete/{categoryId}")
    public BaseResponse<String> delete(@PathVariable String categoryId) {
        return categoryService.delete(categoryId);
    }
}
